/*    */ package com.openbravo.pos.forms;
/*    */ 
/*    */ import com.openbravo.basic.BasicException;
/*    */ import com.openbravo.data.loader.Session;
/*    */ import com.openbravo.pos.util.AltEncrypter;

/*    */ import java.io.File;
/*    */ import java.net.MalformedURLException;
/*    */ import java.net.URI;
/*    */ import java.net.URL;
/*    */ import java.net.URLClassLoader;
/*    */ import java.sql.Driver;
/*    */ import java.sql.DriverManager;
/*    */ import java.sql.SQLException;
/*    */ 
/*    */ public class AppViewConnection
/*    */ {
/*    */   public static Session createSession(AppProperties props)
/*    */     throws BasicException
/*    */   {
/*    */     try
/*    */     {
/* 48 */       if (isJavaWebStart()) {
/* 49 */         Class.forName(props.getProperty("db.driver"), true, Thread.currentThread().getContextClassLoader());
/*    */       } else {
/* 51 */         ClassLoader cloader = new URLClassLoader(new URL[] { new File(props.getProperty("db.driverlib")).toURI().toURL() });
/* 52 */         DriverManager.registerDriver(new DriverWrapper((Driver)Class.forName(props.getProperty("db.driver"), true, cloader).newInstance()));
/*    */       }
/*    */ 
/* 55 */       String sDBUser = props.getProperty("db.user");
/* 56 */       String sDBPassword = props.getProperty("db.password");
/* 57 */       if ((sDBUser != null) && (sDBPassword != null) && (sDBPassword.startsWith("crypt:")))
/*    */       {
/* 59 */         AltEncrypter cypher = new AltEncrypter("cypherkey" + sDBUser);
/* 60 */         sDBPassword = cypher.decrypt(sDBPassword.substring(6));
/*    */       }
/*    */ 
/* 63 */       return new Session(props.getProperty("db.URL"), sDBUser, sDBPassword);
/*    */     }
/*    */     catch (InstantiationException e) {
/* 66 */       throw new BasicException(AppLocal.getIntString("message.databasedrivererror"), e);
/*    */     } catch (IllegalAccessException eIA) {
/* 68 */       throw new BasicException(AppLocal.getIntString("message.databasedrivererror"), eIA);
/*    */     } catch (MalformedURLException eMURL) {
/* 70 */       throw new BasicException(AppLocal.getIntString("message.databasedrivererror"), eMURL);
/*    */     } catch (ClassNotFoundException eCNF) {
/* 72 */       throw new BasicException(AppLocal.getIntString("message.databasedrivererror"), eCNF); } catch (SQLException eSQL) {
	
	throw new BasicException(AppLocal.getIntString("message.databaseconnectionerror"), eSQL);
/*    */     }
 
/* 74 */     
/*    */   }
/*    */ 
/*    */   private static boolean isJavaWebStart()
/*    */   {
/*    */     try
/*    */     {
/* 81 */       Class.forName("javax.jnlp.ServiceManager");
/* 82 */       return true; } catch (ClassNotFoundException ue) {
/*    */     }
/* 84 */     return false;
/*    */   }
/*    */ }

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.forms.AppViewConnection
 * JD-Core Version:    0.6.0
 */